# -*- coding: iso-8859-1 -*-
#
#    This is part of Malvinas Argentinas Messenger
#
#    Malvinas Argentinas Messenger is free software; you can redistribute
#    it and/or modify it under the terms of the GNU General Public License
#    as published by the Free Software Foundation; either version 2 of the
#    License, or (at your option) any later version.
#
#    Malvinas Argentinas Messenger is distributed in the hope that it will be
#    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Malvinas Argentinas Messenger; if not, write to the Free 
#    Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 
#    MA  02110-1301  USA

from protocol import msnlib
import gettext
_ = gettext.gettext

def handleOption(mam):
	# Check if its neccesary to send offline messages
	if mam.ui.status in ['FLN', 'HDN']:
		checkOffMsgs = 1
	else:
		checkOffMsgs = 0
	if mam.ui.options_index == 0:
		mam.m.change_status(msnlib.reverse_status['NLN'], mam.ui.msn_obj)
		new_status = 'NLN'
	elif mam.ui.options_index == 1:
		mam.m.change_status(msnlib.reverse_status['BRB'], mam.ui.msn_obj)
		new_status = 'BRB'
	elif mam.ui.options_index == 2:
		mam.m.change_status(msnlib.reverse_status['LUN'], mam.ui.msn_obj)
		new_status = 'LUN'
	elif mam.ui.options_index == 3:
		mam.m.change_status(msnlib.reverse_status['PHN'], mam.ui.msn_obj)
		new_status = 'PHN'
	elif mam.ui.options_index == 4:
		mam.m.change_status(msnlib.reverse_status['BSY'], mam.ui.msn_obj)
		new_status = 'BSY'
	elif mam.ui.options_index == 5:
		mam.m.change_status(msnlib.reverse_status['AWY'], mam.ui.msn_obj)
		new_status = 'AWY'
	elif mam.ui.options_index == 6:
		mam.m.change_status(msnlib.reverse_status['IDL'], mam.ui.msn_obj)
		new_status = 'IDL'
	elif mam.ui.options_index == 7:
		mam.m.change_status(msnlib.reverse_status['HDN'], mam.ui.msn_obj)
		new_status = 'HDN'
	mam.ui.status = new_status
	if checkOffMsgs:
		mam.checkToSendOffline()
	mam.ui.options_index = -1
	mam.ui.options_list = 0
	mam.ui.winOptMenu.erase()
	mam.ui.winOptMenu.refresh()
	mam.ui.build_barHeader()
	mam.ui.build_barRight()
	del mam.ui.winOptMenu
	mam.ui.refreshScr()
	if not mam.connectionManager.connectStatus:
		mam.connect(new_status)
		mam.ui.options.list[mam.ui.options.nametoIndex(_("Change nick"))].available = 1
		mam.ui.options.list[mam.ui.options.nametoIndex(_("Change configuration"))].available = 0
		#mam.ui.options.list[mam.ui.options.nametoIndex(_("Files transfer"))].available = 0
		#mam.ui.options.list[mam.ui.options.nametoIndex(_("Show logs"))].available = 0
		#mam.ui.options.list[mam.ui.options.nametoIndex(_("Show lists"))].available = 0
		mam.ui.options.list[mam.ui.options.nametoIndex(_("Handle contacts/groups"))].available = 1
		mam.ui.scrList.build_entire_scrList()
		mam.ui.scrList.build_visible_scrList()
		mam.ui.scrList.print_scrList()
